package com.example.demo.dao.impl;

import com.example.demo.dao.BaseDaoImpl;
import com.example.demo.dao.IAccountDao;
import com.example.demo.dao.IExchangeRateDao;
import com.example.demo.jooq.tables.pojos.ExchangeRate;
import com.example.demo.model.po.AccountPage;
import com.example.demo.model.request.AccountPageRequest;
import com.example.demo.util.AssertUtils;
import com.example.demo.util.DateUtils;
import org.jooq.Condition;
import org.jooq.Record;
import org.jooq.SelectJoinStep;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

import static com.example.demo.jooq.tables.Account.ACCOUNT;
import static com.example.demo.jooq.tables.ExchangeRate.EXCHANGE_RATE;
import static com.example.demo.jooq.tables.Virtual.VIRTUAL;
import static com.example.demo.jooq.tables.VisaCard.VISA_CARD;
import static com.example.demo.jooq.tables.Vps.VPS;
import static org.jooq.impl.DSL.count;

@Component
public class IExchangeRateDaoImpl extends BaseDaoImpl implements IExchangeRateDao {
    @Override
    public ExchangeRate queryOneExchangeRate(String from, String to) {
        return this.getDslContext()
                .select(EXCHANGE_RATE.fields())
                .from(EXCHANGE_RATE)
                .where(EXCHANGE_RATE.FROM_CURRENCY.eq(from))
                .and(EXCHANGE_RATE.TO_CURRENCY.eq(to))
                .orderBy(EXCHANGE_RATE.CREATED_DATE.desc())
                .limit(1).fetchOneInto(ExchangeRate.class);
    }
}
